define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'member/account/index' + location.search,
                    add_url: 'member/account/add',
                    // edit_url: 'member/account/edit',
                    // del_url: 'member/account/del',
                    multi_url: 'member/account/multi',
                    import_url: 'member/account/import',
                    table: 'account',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        // {field: 'countrycode', title: __('Countrycode'), operate: 'LIKE'},
                        {field: 'username', title: __('Username'), operate: false,},
                        // {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        // {field: 'password', title: __('Password'), operate: 'LIKE'},
                        // {field: 'salt', title: __('Salt'), operate: 'LIKE'},
                        // {field: 'avatar', title: __('Avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'email', title: __('Email'), operate: 'LIKE'},
                        // {field: 'loginfailure', title: __('Loginfailure')},
                        // {field: 'successions', title: __('Successions')},
                        // {field: 'maxsuccessions', title: __('Maxsuccessions')},
                        // {field: 'prevtime', title: __('Prevtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'logintime', title: __('Logintime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'operationtime', title: __('Operationtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'loginip', title: __('Loginip'), operate: 'LIKE'},
                        // {field: 'joinip', title: __('Joinip'), operate: 'LIKE'},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'token', title: __('Token'), operate: 'LIKE'},
                        // {field: 'status', title: __('Status'), operate: 'LIKE', formatter: Table.api.formatter.status},
                        {field: 'mobile', title: __('Mobile'), operate: false},
                        // {field: 'serial', title: __('Serial')},
                        // {field: 'position', title: __('Position'), operate: 'LIKE'},
                        // {field: 'introduction', title: __('Introduction'), operate: 'LIKE'},
                        // {field: 'selfTag', title: __('Selftag'), operate: 'LIKE'},
                        // {field: 'selfConf', title: __('Selfconf'), operate: 'LIKE'},
                        // {field: 'source', title: __('Source'), searchList: {"0":__('Source 0'),"1":__('Source 1'),"2":__('Source 2'),"3":__('Source 3'),"4":__('Source 4'),"5":__('Source 5')}, formatter: Table.api.formatter.normal},
                        // {field: 'oemKey', title: __('Oemkey'), operate: 'LIKE'},
                        // {field: 'loginCount', title: __('Logincount'), operate: 'LIKE'},
                        // {field: 'QQKey', title: __('Qqkey'), operate: 'LIKE'},
                        // {field: 'wechatKey', title: __('Wechatkey'), operate: 'LIKE'},
                        // {field: 'QQKeyYhy', title: __('Qqkeyyhy'), operate: 'LIKE'},
                        // {field: 'wechatKeyYhy', title: __('Wechatkeyyhy'), operate: 'LIKE'},
                        // {field: 'microblogKey', title: __('Microblogkey'), operate: 'LIKE'},
                        // {field: 'TLS', title: __('Tls'), searchList: {"1":__('Tls 1'),"0":__('Tls 0')}, formatter: Table.api.formatter.normal},
                        // {field: 'isOld', title: __('Isold'), searchList: {"0":__('Isold 0'),"1":__('Isold 1')}, formatter: Table.api.formatter.normal},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            // 获取选中项
            $(document).on("click", ".btn-selected", function () {
                var data= JSON.stringify(table.bootstrapTable('getSelections'));
                var url = $(this).attr('data-url');
                var aid = $(this).attr('data-value');
                if(!url) return false;
                Fast.api.ajax({
                    url:url,
                    type:'post',
                    data:{data:data,aid:aid},
                    dataType: "json",
                }, function(data, ret){
                    //成功的回调
                    Layer.alert(ret.msg);
                    Fast.api.close(data);
                   // table.bootstrapTable('refresh', {});
                   // Layer.close();
                     window.parent.location.reload();
                   // Layer.closeAll();
                   // return false;
                }, function(data, ret){
                    //失败的回调
                    Layer.alert(ret.msg);
                    Fast.api.close(data);
                    window.parent.location.reload();
                   // layer.alert(ret.msg);
                    //return false;
                });
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});